package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.entity.SysMember;
import com.ruoyi.system.mapper.MemberMapper;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author czg
 * @date 2021/9/10 6:31 下午
 */
@Api(tags = "会员管理")
@RestController
@RequestMapping("/api/member")
public class MemberController {

    @Autowired
    MemberMapper memberMapper;

    @PostMapping("/add")
    @ApiOperation("新增会员")
    public AjaxResult addMember(@RequestBody SysMember sysMember) {
        sysMember.setCreateTime(new Date());
        memberMapper.insert(sysMember);
        return AjaxResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除会员")
    public AjaxResult deleteMember(@PathVariable String id) {
        memberMapper.deleteById(id);
        return AjaxResult.success();
    }


    @PutMapping("/update")
    @ApiOperation("修改会员")
    public AjaxResult updateMember(@RequestBody SysMember sysMember) {
        memberMapper.updateById(sysMember);
        return AjaxResult.success();
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("会员详情")
    public AjaxResult<SysMember> getSingleMember(@PathVariable String id) {
        return AjaxResult.success(memberMapper.selectById(id));
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("会员列表")
    public AjaxResult<List<SysMember>> memberList() {
        return AjaxResult.success(memberMapper.selectList(null));
    }
}
